package cn.edu.buaa.sei.jdat.search.trie;

import java.util.LinkedList;
import java.util.List;

public class DomainNode<T> {
	protected String name;
	protected T data;
	
	protected List<DomainNode<T>> children;
	
	protected DomainNode(String name) {
		this.data = null;
		this.name = name;
		children = null;
	}
	
	protected void add(DomainNode<T> node) {
		if (children == null)
			children = new LinkedList<DomainNode<T>>();
		for (DomainNode<T> n : children) {
			int cmp = node.name.compareToIgnoreCase(n.name);
			if (cmp == 0)
				return;
			else if (cmp < 0) {
				int loc = children.indexOf(n);
				children.add(loc, node);
				return;
			}
		}
		children.add(node);
	}
	
	protected void remove(DomainNode<T> node) {
		children.remove(node);
	}
	
	public T getData() {
		return data;
	}
	
	public String debug_name() {
		return name;
	}
}
